

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>内容数据列表</title>
  <meta name="renderer" data="webkit">
  <meta http-equiv="X-UA-Compatible" data="IE=edge,chrome=1">
  <meta name="viewport" data="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="__PUBLIC__/style/admin.css" media="all">
</head>
<body>  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body">
            <div class="test-table-reload-btn" style="margin-bottom: 10px;">
              <div class="layui-form">
                <div class="layui-inline">
                  <input class="layui-input" name="keyword" autocomplete="off" placeholder="搜索IP/HTTP头/内容">
                </div>
                <button class="layui-btn" lay-submit lay-filter="search-submit">搜索</button>
                <button class="layui-btn layui-bg-blue" id="exportAll-btn">导出所有数据</button>
                <button class="layui-btn layui-bg-red" id="deleteAll-btn">清空内容</button>
              </div>
            </div>
            <blockquote class="layui-elem-quote layui-quote-nm">脚本地址：<a href="{$getscript}?id={$project_id}" target="_blank"  style="color:#1e9fff">{$getscript}?id={$project_id}</a></blockquote>
            <table class="layui-hide" id="project-data-table"></table>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="__PUBLIC__/layui/layui.js"></script>

  <script type="text/html" id="headerTpl">
    {{# var json_header = JSON.parse(d.header);}}
    {{# layui.each(json_header, function(index, item){     }}
      <p>【<span class="layui-font-green">{{ index}}</span>】{{item}}</p>
    {{# });  }}
  </script>
  <script type="text/html" id="dataTpl">
    {{# var json_data = JSON.parse(d.data);}}
    {{# layui.each(json_data, function(index, item){     }}
      <p>【<span class="layui-font-green">{{ index}}</span>】{{item}}</p>
    {{# });  }}
  </script>

  <script>
  var currPage = 1;
  layui.config({
    base: '__PUBLIC__/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table', 'form','util'], function(){
    var table = layui.table,form = layui.form,$ = layui.$,util = layui.util;
  
    //动态加载数据记录表
    function renderTb(keywd){
      var where = {project_id: {$project_id}, keyword: keywd};
      table.render({
        elem: '#project-data-table'
        ,url: "{:U('Ajax/ajax_project_data_list')}"
        ,cellMinWidth: 80
        ,limit: 20
        ,page: true
        ,where:where
        ,cols: [[
          {field:'id', width:80, title: 'ID'}
          ,{field:'ip', width:160, title: '对端IP'}
          ,{field:'header', title: 'HTTP头', templet:'#headerTpl'}
          ,{field:'data',  title: '内容', templet:'#dataTpl'}
          ,{field:'time', width:160, title: '时间', templet: 
            function(d){ return util.toDateString(d.time*1000, 'yyyy-MM-dd HH:mm:ss');}
          } 
        ]]
        ,cellExpandedMode:'tips'
        ,defaultToolbar: [
          'filter', // 列筛选
          'exports', // 导出
        ]
        ,toolbar: true
        //,defaultToolbar: ['filter','exports']
        ,done: function(res, curr, count){
          currPage = curr;
        }
      });
    }
    
    // 动态加载数据
    renderTb('');

    // 搜索数据记录
    form.on('submit(search-submit)', function(obj){
      renderTb(obj.field.keyword);
    });

    //清空内容
    $('#deleteAll-btn').on('click', function() {
      layer.confirm('你确定要清空所有数据吗？', {
        title: '清空数据',
        btn: ['确定', '取消']
      }, function(index, layero) {
        $.post("{:U('Ajax/ajax_project_data_deleteall')}", JSON.stringify({project_id: {$project_id}}),function(d){
          if(d.code == 0){
            renderTb('');
          }
          layer.msg(d.msg);
        },"json");
        layer.close(index);
      }, function(index, layero) {
        layer.close(index);
      });
     
    });

    // 导出所有数据
    $('#exportAll-btn').on('click', function() {
      window.location.href = "{:U('Project/project_data_download')}?project_id="+{$project_id};
    });
  });
  //刷新用户表
  function refreshTable(){
    layui.table.reload('project-data-table', {
        url: "{:U('Ajax/ajax_project_data_list')}",
        page: {
          curr: currPage
        }
    });
  }
  </script>
</body>
</html>